const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
    mode: 'development',
    entry: path.resolve(__dirname, './src/index.tsx'),
    output: {
        filename: 'bundle.js',
        path: path.join(__dirname, './dist'),
        publicPath: '/'
    },
    devtool: 'source-map',
    devServer: {
        contentBase: path.join(__dirname, './dist'),
        hot: true,
        //无法响应的路由都会重定向到首页
        historyApiFallback: true
    },
    resolve: {
        alias:{
            '@':path.resolve(__dirname, 'src')
        },
        extensions: ['.tsx', '.ts', '.js', '.json']
    },
    module: {
        rules: [
            {
                test: /\.tsx$/,
                use: ['ts-loader', 'source-map-loader']
            },
            {
                enforce: 'pre',
                test: /\.tsx$/,
                loader: 'source-map-loader'
            },
            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 512
                    }    
                }],
            }
        ]
    },
    plugins: [
        new htmlWebpackPlugin({
            template: './src/common/index.html',
            filename: 'index.html'
        }),
        new webpack.HotModuleReplacementPlugin()
    ]
}